﻿using System;
using System.Configuration;

namespace Navigant.Infrastructure.Helpers
{
    public static class UriExtensions
    {
        public static Uri ToValidUri(this Uri address)
        {
            Uri validUri = address;
            // Account for the fact the Scheme (protocol) of the 
            // Case Uri may be incorrect
            string protocol = ConfigurationManager.AppSettings["Protocol"];
            if (!string.IsNullOrEmpty(protocol) &&
                address.Scheme.ToLower() != protocol.ToLower())
            {
                string url = address.AbsoluteUri.Replace(address.Scheme, protocol);
                validUri = new Uri(url);
            }
            return validUri;
        }
    }
}
